<template>
	<view class="app">
		<view class="tabs-div"><u-tabs :list="btnList" @click="clickTabs"></u-tabs></view>
		<u-gap height="80rpx"></u-gap>
		<view class="">
			<u-list @scrolltolower="scrolltolower" height="calc(100vh - 80rpx)"  :scrollIntoView="o_id">
				<u-list-item v-for="(item, index) in List" :key="index" :id="'o_' + index">
					<view class="u-p-32 content-box">
						<view class=" u-flex">
							<view class="u-flex-3">
								<view class="u-m-b-20">
									<text>抬头:</text>
									<text>{{ item.rise }}</text>
								</view>
								<view class="u-m-b-20">
									<text>税号:</text>
									<text>{{ item.duty_paragraph }}</text>
								</view>
								<view class="u-m-b-20">
									<text>发票类型:</text>
									<text>{{ item.invoice_type == 1 ? '个体' : '企业' }}</text>
								</view>
								<view class="u-m-b-20">
									<text>订单编号:</text>
									<text>{{ item.order.order_no }}</text>
								</view>
								<view>
									<text>状态:</text>
									<text>{{ item.status }}</text>
								</view>
							</view>
						</view>
						<u-line margin="20rpx 0"></u-line>
						<view class="btn u-flex">
							<u-button shape="circle" customStyle="width:160rpx;margin:0 10rpx" size="small" type="primary" @click="orderDetails(item.order.id)">查看订单</u-button>
							<u-button
								shape="circle"
								customStyle="width:160rpx;margin:0 10rpx"
								size="small"
								type="primary"
								v-if="item.status == '未审核'"
								@click="itemShow(item.id, index, 1)"
							>
								审核
							</u-button>
							<u-button shape="circle" customStyle="width:160rpx;margin:0 10rpx" size="small" type="primary" @click="itemShow(item.id, index, 0)">查看</u-button>
						</view>
					</view>
				</u-list-item>
				<u-loadmore @loadmore="getDataList" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
			</u-list>
		</view>
		<u-popup :show="show">
			<u-form ref="invoiceListRef" :model="editInvoiceList" label-width="80px" class="u-p-20">
				<u-form-item label="抬头">{{ editInvoiceList.rise }}</u-form-item>
				<u-form-item label="税号">{{ editInvoiceList.duty_paragraph }}</u-form-item>
				<u-form-item label="银行账号">{{ editInvoiceList.bank_account }}</u-form-item>
				<u-form-item label="手机号码">{{ editInvoiceList.phone }}</u-form-item>
				<u-form-item label="地址">{{ editInvoiceList.address }}</u-form-item>
				<u-form-item label="邮箱">{{ editInvoiceList.mailbox }}</u-form-item>

				<u-form-item label="状态" v-if="isedit">
					<u-radio-group v-model="editInvoiceList.status">
						<u-radio customStyle="margin-right:32rpx" :name="item.value" v-for="(item, i) in options" :label="item.label"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="状态" v-else>{{ editInvoiceList.status }}</u-form-item>
				<u-form-item label="备注" v-if="isedit"><u-input type="textarea" v-model="editInvoiceList.remake"></u-input></u-form-item>
				<u-form-item label="状态" v-else>{{ editInvoiceList.remake }}</u-form-item>
			</u-form>
			<view class="u-flex u-flex-items-center footer">
				<u-button size="small" shape="circle" @click="show = false">关闭</u-button>
				<u-button v-if="isedit" class="u-m-l-60" type="primary" size="small" shape="circle" @click="saveData">确定</u-button>
			</view>
		</u-popup>
		<lc-fab-touch ref="fab" :content="contents" horizontal="right" vertical="bottom" direction="horizontal" @trigger="trigger" />
		
	</view>
</template>
<script>
export default {
	data() {
		return {
			obj: {
				page: 1,
				size: 10,
				inoice_type: 0,
				status: 0
			},
			objTemp: {},
			isLoading: false,
			List: [],
			status: 'loadmore',
			loadingText: '努力加载中',
			loadmoreText: '上拉或点击加载更多',
			nomoreText: '实在没有了',
			show_model: false,
			content: '',
			btnList: [
				{
					name: '全部'
				},
				{
					name: '未审核'
				},
				{
					name: '已通过'
				},
				{
					name: '驳回'
				}
			],
			options: [
				{
					value: 2,
					label: '已通过'
				},
				{
					value: 3,
					label: '驳回'
				}
			],
			btn_type: -1,
			editInvoiceList: {},
			show: false,
			isedit: false,
			o_id: '',
			contents: [
				{
					iconPath: 'arrow-up',
					selectedIconPath: 'arrow-up',
					text: '顶部',
			
					active: false
				},
				{
					iconPath: 'home',
					selectedIconPath: 'home-fill',
					text: '首页',
					active: false
				}
			],
		};
	},
	components: {},
	onLoad() {
		this.searchList();
	},
	onPullDownRefresh() {
		this.searchList()
	},
	methods: {
		trigger(e) {
			if (e.index == 0) {
				this.o_id = '';
				this.$nextTick(() => {
					this.o_id = 'o_0';
				});
			} else if (e.index == 1) {
				uni.$u.route({
					url: 'pages/index/index'
				});
			}
		},
		scrolltolower() {
			this.getDataList();
		},
		orderDetails(id){
			uni.$u.route({
				url: 'pages/order/detail?id=' + id
			});
		},
		changelist(id) {
			uni.$u.http
				.get('/shop/invoice/manage/read', {params: {id: id},custom:{id:12}})
				.then(res => {
					let detail = res.msg;
					// this.List[this.index] = detail;
					this.List[this.index].status = detail.status;
					this.List[this.index].update_time = detail.update_time;

					this.show = false;
				})
				.catch(err => {});
		},

		//查询数据
		searchList() {
			//复制查询对象
			this.objTemp = {...this.obj};
			this.List = [];
			this.objTemp.page = 1;
			this.getDataList();
		},
		//查询数据本体
		getDataList() {
			this.isLoading = true;
			uni.$u.http
				.get('/shop/invoice/manage/invoiceList', {params: this.objTemp,custom:{id:12}})
				.then(res => {
					this.isLoading = false;
					uni.stopPullDownRefresh();
					let json = res.msg;
					if (json.data.length > 0) {
						this.objTemp.page++;
						let list = json.data;

						this.List = this.List.concat(list);
					} else {
						this.status = 'nomore';
					}
				})
				.catch(e => {
					this.isLoading = false;
				});
		},
		itemShow(id, index, isedit) {
			this.index = index;
			this.isedit = isedit;
			uni.$u.http.get('/shop/invoice/manage/read', {params: {id: id},custom:{id:12}}).then(res => {
				this.editInvoiceList = res.msg;
				this.editInvoiceList.status = 2;
				this.show = true;
			});
		},
		// 提交审核
		saveData() {
			let data = {
				id: this.editInvoiceList.id,
				status: this.editInvoiceList.status,
				remake: this.editInvoiceList.remake
			};
			uni.$u.http.put('/shop/invoice/manage/examine', data,{custom:{id:12}}).then(res => {
				this.changelist(this.editInvoiceList.id);
			});
		},
		clickTabs(data) {
			let index = data.index;
			this.obj.status = index;

			this.searchList();
		}
	}
};
</script>
<style lang="scss">
.content-box {
	margin: 20rpx auto;
	position: relative;
	font-size: 28rpx;
}
.search-box {
	width: 520rpx;
}
.tabs-div {
	top: 0;
}
</style>
